package org.geektimes.util;

import java.util.concurrent.*;

public class ThreadPoolFutureTaskDemo implements Callable<String> {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        final ThreadPoolFutureTaskDemo threadPoolFutureTaskDemo = new ThreadPoolFutureTaskDemo();

        final ExecutorService executorService = Executors.newFixedThreadPool(2);
        final Future<?> submit = executorService.submit(threadPoolFutureTaskDemo);
        System.out.println(submit.get());
    }

    /**
     * Computes a result, or throws an exception if unable to do so.
     *
     * @return computed result
     * @throws Exception if unable to compute a result
     */
    @Override
    public String call() throws Exception {
        Thread.sleep(2000000000);
        return "hello world";
    }
}
